import sys
import re
from typing import Dict, Callable, Iterable


class Parameter(object):
    _PATTERN_PARAM = re.compile(r'(-|--)\w+')

    def parse(self) -> bool:
        parser = self._on_begin()

        params = sys.argv[1:]
        while len(params) > 0 and Parameter._PATTERN_PARAM.match(params[0]):
            if params[0] not in parser:
                return False

            count = parser[params[0]](params[1:])
            if count < 0:
                return False

            params = params[count + 1:]

        return self._on_end()

    def _on_begin(self) -> Dict[str, Callable[[Iterable[str]], int]]:
        # implement by child
        pass

    def _on_end(self) -> bool:
        # implement by child
        pass
